//
//  PersonViewController.swift
//  ShiZhe
//
//  Created by 陈卿伟 on 16/9/11.
//  Copyright © 2016年 陈卿伟. All rights reserved.
//

import UIKit

class PersonViewController: UIViewController {
    var tableView:PersonTableView!
    var firstCell:FirstCell!//第一个cell
    var personCell:PersonCell!//中间几个cell
    var footerCell:FooterCell!//有图片的cell
    
    var personArr = ["用户名","个性签名","性别","生日","地区","绑定银行卡"]
    var personRightArr = ["就说还有谁","天若有情天亦老，我只想要吃好，喝好，睡好，拉屎好","男","1993-12-29","浙江·温州","已绑定"]
    var centerString = "(绑定银行卡后可将您的收入取现)"
    
    var footImage = ["wechatP","QQP","weiboP"]
    var footerLeftArr = ["微信","QQ","微博"]
    var footerRightArr = ["已绑定","未绑定","已绑定"]
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "个人资料"
        self.addtableViewToControll()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

}

//MARK:--UI
extension PersonViewController{
    //添加tableView进来
    func addtableViewToControll(){
        tableView = PersonTableView(frame: MainBounds, style: .Grouped)
        tableView.delegate = self
        tableView.dataSource = self
        self.view.addSubview(tableView)
    }
}

//MARK:--tableView  delegate  datasoure
extension PersonViewController:UITableViewDelegate,UITableViewDataSource{
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 4
    }
    
    func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 15
    }
    
    func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        switch section {
        case 0:
            return 1
        case 1:
            return 5
        case 2:
            return 1
        case 3:
            return 3
        default:
            return 0
        }
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        switch (indexPath as NSIndexPath).section {
        case 0:
            firstCell = FirstCell(style: .Default, reuseIdentifier: "personFirstCell")
            tableView.rowHeight = 80*SCALEH
            return firstCell
        case 1,2:
            personCell = PersonCell(style: .Default, reuseIdentifier: "personCell")
            tableView.rowHeight = 40*SCALEH
            personCell.leftLabel.text = personArr[(indexPath as NSIndexPath).row]
            personCell.rightLabel.text = personRightArr[(indexPath as NSIndexPath).row]
            if (indexPath as NSIndexPath).section == 2{
                personCell.leftLabel.text = personArr[(indexPath as NSIndexPath).row+5]
                personCell.rightLabel.text = personRightArr[(indexPath as NSIndexPath).row+5]
                personCell.centerLabel.text = centerString
            }
            return personCell
        default:
            footerCell = FooterCell(style: .Default, reuseIdentifier: "footerCell")
            tableView.rowHeight = 40*SCALEH
            footerCell.iconImage.image = UIImage(named: footImage[(indexPath as NSIndexPath).row])
            footerCell.leftLabel.text = footerLeftArr[(indexPath as NSIndexPath).row]
            footerCell.rightLabel.text = footerRightArr[(indexPath as NSIndexPath).row]
            return footerCell
        }
    }
}









